package enumandlambda;

/**
 * @author shkstart
 * @create 2022-11-29-13:22
 */
public class ThreadDemoByPriority2 {
    private final static int MAXCOUNT = 1000;
    public static void main(String[] args) {
        Thread t1 = new Thread(new Runnable() {

            @Override
            public void run() {

                Thread t = Thread.currentThread();
                int priority = t.getPriority();
                for (int i = 0; i < MAXCOUNT; i++) {
                    System.out.println(t.getName()+"-优先级"+ priority);
                }
            }
        },"线程1");
//        t1.setPriority(10);
        //设置线程优先级
        t1.setPriority(Thread.MAX_PRIORITY);

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                Thread t = Thread.currentThread();
                int priority = t.getPriority();
                for (int i = 0; i < MAXCOUNT; i++) {
                    System.out.println(t.getName()+"-优先级"+ priority);
                }
            }
        },"线程2");
        t2.setPriority(Thread.MIN_PRIORITY);

        Thread t3 = new Thread(new Runnable() {
            @Override
            public void run() {
                Thread t = Thread.currentThread();
                int priority = t.getPriority();
                for (int i = 0; i < MAXCOUNT; i++) {
                    System.out.println(t.getName() + "-优先级" + priority);
                }
            }
        }, "线程3");
        t3.setPriority(Thread.NORM_PRIORITY);

        //同时启动
        t2.start();
        t1.start();
        t3.start(); 

    }
}
